#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>

typedef struct TreeNode {
      int val;
      struct TreeNode *left;
      struct TreeNode *right;
}TreeNode;

void preorder(struct TreeNode* root, int* arr, int* returnsize) {
    if (root == NULL) {
        return;
    }
    arr[(*returnsize)++] = root->val;
    preorder(root->left, arr, returnsize);
    preorder(root->right, arr, returnsize);
}

int* preorderTraversal(struct TreeNode* root, int* returnSize) {
    int* arr = (int*)malloc(sizeof(int) * 2000);
    *returnSize = 0;
    preorder(root, arr, returnSize);
    return arr;
}

int main() {
    TreeNode* node1 = (TreeNode*)malloc(sizeof(TreeNode));
    TreeNode* node2 = (TreeNode*)malloc(sizeof(TreeNode));
    TreeNode* node3 = (TreeNode*)malloc(sizeof(TreeNode));
    node1->left = NULL;
    node1->val = 1;
    node1->right = node2;
    node2->left = node3;
    node2->right = NULL;
    node2->val = 2;
    node3->val = 3;
    node3->left = NULL;
    node3->right = NULL;
    int* returnsize = (int*)malloc(sizeof(int));
    *returnsize = 0;
    int* arr = preorderTraversal(node1, returnsize);
}